/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : MyComputer
 * @DateTime : 2024/5/7 15:01
 */

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int compress(vector<char> &chars) {
        int len = 0;
        for (int i = 0; i < chars.size(); ++i) {
            char ch = chars[i];
            int j = i + 1;
            while (j < chars.size() && chars[j] == ch) j++;
            int x = j - i;
            len++;
            if (x == 1) continue;
            string s = to_string(x);
            len += s.size();
            for (int k = 0; k < s.size(); ++k) {
                chars[i + k + 1] = s[k];
            }
            for (int l = i + s.size() + 1, r = j; r < chars.size(); ++r, ++l) {
                chars[l] = chars[r];
            }
            i = i + s.size();
        }
        chars.erase(chars.begin()+len,chars.end());
        return len;
    }
};

int main() {

    return 0;
}